//
//  VoteItem.m
//  CLUBiN
//
//  Created by Stefan Ivanov on 1/13/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "VoteItem.h"

@implementation VoteItem

@synthesize first, second, third;
@synthesize date, time;

//initialization method for creating an instance
- (id)initWithFirst: (MusicItem*)f Second: (MusicItem*)s Third: (MusicItem*)t
{
    self.first = f;
    self.second = s;
    self.third = t;
    
    //make a date and a time formatter
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    
    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm:ss"];
    
    //get the current date time information
    NSDate *now = [[NSDate alloc] init];
    
    //initialize the date and time vars
    self.date = [dateFormat stringFromDate:now];
    self.time = [timeFormat stringFromDate:now];
    
    //clean up 
    [dateFormat release];
    [timeFormat release];
    [now release];
    
    return self;
}

//below is the implementation of the two methods required by the NSCoding protocol
-(id) initWithCoder: (NSCoder*) coder {
    if (self == [super init]) {
        self.first = [[coder decodeObjectForKey:@"First"] retain];
        self.second = [[coder decodeObjectForKey:@"Second"] retain];
        self.third = [[coder decodeObjectForKey:@"Third"] retain];
        self.date = [[coder decodeObjectForKey:@"Date"] retain];
        self.time = [[coder decodeObjectForKey:@"Time"] retain];
    }
    return self;
}


-(void) encodeWithCoder: (NSCoder*) coder {
    [coder encodeObject:self.first forKey:@"First"]; 
    [coder encodeObject:self.second forKey:@"Second"]; 
    [coder encodeObject:self.third forKey:@"Third"]; 
    [coder encodeObject:self.date forKey:@"Date"];
    [coder encodeObject:self.time forKey:@"Time"];
}

@end
